package com.nanhai.buddhist.college.module.study.controller.admin.teacherevaluation;

import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.*;

import javax.validation.constraints.*;
import javax.validation.*;
import javax.servlet.http.*;
import java.util.*;
import java.io.IOException;

import com.nanhai.buddhist.college.framework.common.pojo.PageResult;
import com.nanhai.buddhist.college.framework.common.pojo.CommonResult;
import static com.nanhai.buddhist.college.framework.common.pojo.CommonResult.success;

import com.nanhai.buddhist.college.framework.excel.core.util.ExcelUtils;

import com.nanhai.buddhist.college.framework.operatelog.core.annotations.OperateLog;
import static com.nanhai.buddhist.college.framework.operatelog.core.enums.OperateTypeEnum.*;

import com.nanhai.buddhist.college.module.study.controller.admin.teacherevaluation.vo.*;
import com.nanhai.buddhist.college.module.study.dal.dataobject.teacherevaluation.TeacherEvaluationDO;
import com.nanhai.buddhist.college.module.study.convert.teacherevaluation.TeacherEvaluationConvert;
import com.nanhai.buddhist.college.module.study.service.teacherevaluation.TeacherEvaluationService;

@Api(tags = "管理后台 - 教师评价")
@RestController
@RequestMapping("/study/teacher-evaluation")
@Validated
public class TeacherEvaluationController {

    @Resource
    private TeacherEvaluationService teacherEvaluationService;

    @PostMapping("/create")
    @ApiOperation("创建教师评价")
//    @PreAuthorize("@ss.hasPermission('study:teacher-evaluation:create')")
    public CommonResult<String> createTeacherEvaluation(@Valid @RequestBody TeacherEvaluationCreateReqVO createReqVO) {
        return success(teacherEvaluationService.createTeacherEvaluation(createReqVO));
    }

    @PutMapping("/update")
    @ApiOperation("更新教师评价")
//    @PreAuthorize("@ss.hasPermission('study:teacher-evaluation:update')")
    public CommonResult<Boolean> updateTeacherEvaluation(@Valid @RequestBody TeacherEvaluationUpdateReqVO updateReqVO) {
        teacherEvaluationService.updateTeacherEvaluation(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @ApiOperation("删除教师评价")
    @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = String.class)
//    @PreAuthorize("@ss.hasPermission('study:teacher-evaluation:delete')")
    public CommonResult<Boolean> deleteTeacherEvaluation(@RequestParam("id") String id) {
        teacherEvaluationService.deleteTeacherEvaluation(id);
        return success(true);
    }

    @GetMapping("/get")
    @ApiOperation("获得教师评价")
    @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = String.class)
//    @PreAuthorize("@ss.hasPermission('study:teacher-evaluation:query')")
    public CommonResult<TeacherEvaluationRespVO> getTeacherEvaluation(@RequestParam("id") String id) {
        TeacherEvaluationDO teacherEvaluation = teacherEvaluationService.getTeacherEvaluation(id);
        return success(TeacherEvaluationConvert.INSTANCE.convert(teacherEvaluation));
    }

    @GetMapping("/list")
    @ApiOperation("获得教师评价列表")
    @ApiImplicitParam(name = "ids", value = "编号列表", required = true, example = "1024,2048", dataTypeClass = List.class)
//    @PreAuthorize("@ss.hasPermission('study:teacher-evaluation:query')")
    public CommonResult<List<TeacherEvaluationRespVO>> getTeacherEvaluationList(@RequestParam("ids") Collection<String> ids) {
        List<TeacherEvaluationDO> list = teacherEvaluationService.getTeacherEvaluationList(ids);
        return success(TeacherEvaluationConvert.INSTANCE.convertList(list));
    }

    @GetMapping("/page")
    @ApiOperation("获得教师评价分页")
//    @PreAuthorize("@ss.hasPermission('study:teacher-evaluation:query')")
    public CommonResult<PageResult<TeacherEvaluationRespVO>> getTeacherEvaluationPage(@Valid TeacherEvaluationPageReqVO pageVO) {
        PageResult<TeacherEvaluationDO> pageResult = teacherEvaluationService.getTeacherEvaluationPage(pageVO);
        return success(TeacherEvaluationConvert.INSTANCE.convertPage(pageResult));
    }

    @GetMapping("/export-excel")
    @ApiOperation("导出教师评价 Excel")
//    @PreAuthorize("@ss.hasPermission('study:teacher-evaluation:export')")
    @OperateLog(type = EXPORT)
    public void exportTeacherEvaluationExcel(@Valid TeacherEvaluationExportReqVO exportReqVO,
              HttpServletResponse response) throws IOException {
        List<TeacherEvaluationDO> list = teacherEvaluationService.getTeacherEvaluationList(exportReqVO);
        // 导出 Excel
        List<TeacherEvaluationExcelVO> datas = TeacherEvaluationConvert.INSTANCE.convertList02(list);
        ExcelUtils.write(response, "教师评价.xls", "数据", TeacherEvaluationExcelVO.class, datas);
    }


    /**
     * 获取教师评价表的所有学院
     * @return
     */
    @GetMapping("/colleges")
    @ApiOperation("获得教师评价表的所有学院")
//    @PreAuthorize("@ss.hasPermission('study:teacher-evaluation:query')")
    public CommonResult<List<TeacherEvaluationRespVO>> selectAllCollegesList() {
        List<TeacherEvaluationDO> list = teacherEvaluationService.selectAllCollegesList();
        return success(TeacherEvaluationConvert.INSTANCE.convertList(list));
    }


    /**
     * 获取教师评价表的所有班级
     * @return
     */
    @GetMapping("/classes")
    @ApiOperation("获得教师评价表的所有班级")
//    @PreAuthorize("@ss.hasPermission('study:teacher-evaluation:query')")
    public CommonResult<List<TeacherEvaluationRespVO>> selectAllClassesList() {
        List<TeacherEvaluationDO> list = teacherEvaluationService.selectAllClassesList();
        return success(TeacherEvaluationConvert.INSTANCE.convertList(list));
    }

}
